//package com.naiterui.ehp.bs.recommend.dao.impl;
//
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.LinkedHashMap;
//import java.util.List;
//import java.util.Map;
//import java.util.Set;
//
//import org.apache.commons.collections4.CollectionUtils;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.stereotype.Repository;
//
//import com.naiterui.common.repository.hibernate.DefaultBaseDaoImpl;
//import com.naiterui.ehp.bp.utils.lang.StringUtil;
//import com.naiterui.ehp.bs.recommend.bean.MedicationRecomDetail;
//import com.naiterui.ehp.bs.recommend.dao.IMedicationRecomDetailDao;
//
///**
// * @Description 用药推荐详情
// */
//@Repository
//public class MedicationRecomDetailDaoImpl extends DefaultBaseDaoImpl<MedicationRecomDetail, Long> implements IMedicationRecomDetailDao {
//
//    @Override
//    public List<MedicationRecomDetail> getDetailsByRecomId(Long recommendId) {
//        return super.find("from MedicationRecomDetail where recommendId=?", recommendId);
//    }
//
//    @Override
//    public List<MedicationRecomDetail> getDetailsByRecomIdByWrite(Long recommendId) {
//        return super.find("from MedicationRecomDetail where recommendId=?", recommendId);
//    }
//
//
//    @Override
//    public Map<Long, List<MedicationRecomDetail>> getRecomDetails(Set<Long> recommendIds) {
//        Map<Long, List<MedicationRecomDetail>> resultMap = new LinkedHashMap<>();
//        if (recommendIds != null && recommendIds.size() > 0) {
//            String recomIdStr = recommendIds.toString().substring(1, recommendIds.toString().length() - 1);
//            List<MedicationRecomDetail> recoms = super.find("from MedicationRecomDetail where recommendId in (" + recomIdStr + ") ");
//            // 按推荐ID分组推荐商品详情
//            for (MedicationRecomDetail recom : recoms) {
//                if (!resultMap.containsKey(recom.getRecommendId())) {
//                    List<MedicationRecomDetail> recomList = new ArrayList<>();
//                    recomList.add(recom);
//                    resultMap.put(recom.getRecommendId(), recomList);
//                } else {
//                    resultMap.get(recom.getRecommendId()).add(recom);
//                }
//            }
//        }
//        return resultMap;
//    }
//
//
//    @Override
//    public Map<Long, List<MedicationRecomDetail>> getRecomDetails(List<Long> recomIds) {
//        Map<Long, List<MedicationRecomDetail>> map = new HashMap<>();
//        StringBuilder rids = new StringBuilder();
//        for (Long id : recomIds) {
//
//            if (recomIds.indexOf(id) == 0) {
//                rids.append("(").append(id).append(",");
//            }
//            if (recomIds.indexOf(id) == recomIds.size() - 1) {
//                rids.append(id).append(")");
//            } else {
//                rids.append(id).append(",");
//            }
//        }
//
//        // 空数组
//        if (StringUtils.isEmpty(rids.toString())) {
//            return map;
//        }
//        String hql = "FROM MedicationRecomDetail where recommendId in " + rids;
//        List<MedicationRecomDetail> items = this.find(hql);
//        // 按照推荐id对药品分组
//        for (MedicationRecomDetail item : items) {
//            if (map.get(item.getRecommendId()) == null) {// 第一次放入map
//                List<MedicationRecomDetail> details = new ArrayList<>();
//                details.add(item);
//                map.put(item.getRecommendId(), details);
//            } else {
//                map.get(item.getRecommendId()).add(item);
//            }
//        }
//        return map;
//    }
//
//    @Override
//    public List<MedicationRecomDetail> getDetailsByRecomIds(Set<Long> recomIdSet) {
//        if (CollectionUtils.isNotEmpty(recomIdSet)) {
//            String idsStr = StringUtil.convertCollection(recomIdSet);
//            return super.find("from MedicationRecomDetail where recommendId in (" + idsStr + ")");
//        }
//        return new ArrayList<>();
//    }
//}
